package com.jiyun;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;
import java.util.concurrent.TimeUnit;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext-redis.xml")
public class SpringdataRedisDemo_List {

    @Autowired
    RedisTemplate redisTemplate;

    /*
    List类型增删改查  key—[v,v,v,v,v,v,v]
     */

    @Test
    public void add(){
       redisTemplate.boundListOps("names").leftPush("张三");
       redisTemplate.boundListOps("names").leftPush("李四");
       redisTemplate.boundListOps("names").rightPush("王五");
       redisTemplate.boundListOps("names").rightPush("赵六");
       //李四  张三  王五  赵六
    }

    @Test
    public void query(){
        List names = redisTemplate.boundListOps("names").range(0, -1);
        System.out.println(names);
    }

    @Test
    public void delItem(){
        redisTemplate.boundListOps("names").leftPop();
        redisTemplate.boundListOps("names").rightPop();
        //redisTemplate.boundListOps("names").remove(5,"张三");  5个张三
    }

}
